# -*- coding: utf-8 -*-

from w.blocks.containers.block import Block

from w.html.useful import TextInput

class StringField(Block):
    def __init__(self, content=None, name='', fixedSize=None, noSizing=False, defaultClass='', *argv, **kwargv):
        if isinstance(content, list):
            raise ValueError("Content can't be a list")

        self.name=name

        Block.__init__(self, content, *argv, **kwargv)

        self.fixedSize = fixedSize
        self.noSizing = noSizing
        self.tag = TextInput(hclass=defaultClass, hname=self.name)
        self.html = self.tag.html

    def make(self, content=[]):
        if not content:
            content = self
        if content:
            content = content[0]
            self.tag.html.value = content
            if not self.noSizing:
                self.tag.html.size = self.fixedSize if self.fixedSize else len(unicode(content, 'utf-8'))+1+2
        return Block.make(self, [self.tag,])

